#include "spi.h"
//#include "c:\avrtoolbox\libavr\source\driver\spi\spi.h"

void spi0_init_master(void)
{
        PORTB |= (1<< MISO_HARDWARE_PIN) \
                        | (1<< MOSI_HARDWARE_PIN) \
                        | (1<< SCLK_HARDWARE_PIN) \
                        | (1<< SS_HARDWARE_PIN);

        //Set MOSI, SCK AND SS to outputs
        DDRB |= (1<< MOSI_HARDWARE_DDR) \
                        | (1<< SCLK_HARDWARE_DDR) \
                        | (1<< SS_HARDWARE_DDR);

        // Set Miso to input
        DDRB &= ~(1<<MISO_HARDWARE_DDR);


        //SPI double speed settings
        SPSR = (1<<SPI2X);                                      
        //Enable SPI in Master mode, mode 3, Fosc/2
        SPCR = (1<<SPE) | (1<<MSTR) | (1<<CPHA) | (1<<CPOL);    

}
